package sg.edu.nus.iss.myapplet;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;

import javax.swing.*;
import java.util.Properties;

	

	public class HelloWorld extends JFrame  {
		private JLabel label;
		
		public HelloWorld () {
			super("Hello World Application");
			this.setSize(270,70);
			this.setLayout(new FlowLayout());
			
			label = new JLabel ("Hello");
			JButton button = new JButton ("press");
			this.add(label);
			this.add(button);
			
			button.addActionListener(new HelloWorldLister ());
		}
		
		public HelloWorld(int n){
			super("Hello World Application");
			//this.setSize(270,70);
			this.setLayout(new FlowLayout());
			
			CheckboxGroup cbg = new CheckboxGroup();
			for (int i =1 ; i <= n; i ++) {
				Checkbox cb = new Checkbox ("press" + i, cbg, false);
				this.add(cb);
			}
		}
		

		class HelloWorldLister implements ActionListener {
			public void actionPerformed (ActionEvent e) {
				if (getLabelText().equals("Goodbye")){
					setLabelText ("Welcome");
				}else {
					setLabelText ("Goodbye");
				}
			}
		}
		
		public void setLabelText (String newLabelText) {
			label.setText(newLabelText);
		}
		
		public String getLabelText () {
			return label.getText();
		}
		
		
	
	
	
	public static void main(String[] args) throws Exception{
		
		/* Test read Properties
		final String PRO_FILE = ".\\conf\\a.txt";
		Properties appProps = new Properties();
		FileInputStream in = new FileInputStream (PRO_FILE);
		appProps.load(in);
		in.close();
		int size = Integer.parseInt((String)appProps.get("size"));
		System.out.println(size);
		*/
		// TODO Auto-generated method stub
		//HelloWorld frame = new HelloWorld();
		HelloWorld frame = new HelloWorld(5);
		frame.pack();
		
		frame.setVisible(true);
	
	
	}
}
	

